<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-07-12 10:56:47
 * @LastEditors: charles
 * @LastEditTime: 2021-08-01 14:08:29
-->
<template>
  <div class="projects">
        <div class="wrapper">
          <div class="title">研学精选项目</div>
          <div @click="projectHandler(item.id)" class="project" v-for='item in articles' :key="item.id">
            <div class="left">
              <img width="100%" :src="item.cover" alt="">
            </div>
            <div class="right">
              <div class="name">{{item.title}}</div>
              <div class="time">{{item.publishTime}}</div>
              <div class="content">阅读次数：{{item.readTimes}}点赞次数：{{item.thumpUp}}</div>
            </div>
          </div>
        </div>
    </div>
</template>
<script>
import {get} from '../utils/request'
export default {
  data(){
    return {
      categoryId:this.$route.query.categoryId,
      //向后台传递的参数
      list:{
        page:1,
        pageSize:10,
        categoryId:this.$route.query.categoryId
      },
      articles:[]
    }
  },
  //帧听器
  watch:{
    '$route.query.categoryId':function(){
      this.list.categoryId = this.$route.query.categoryId;
      //刷新页面
      this.findArtilceById()
    }
  },
  methods:{
    //通过categoryId查询资讯信息
    findArtilceById(){
      //数据交互
      get('/index/article/pageQuery',this.list).then(res=>{
        if(res.status == 200){
            this.articles = res.data.list
        }else {
          this.$message({
            type:"error",
            message:res.message
          })
        }
      })
    }
  },
  created(){
    this.findArtilceById()
  }
}
</script>

<style scoped lang='scss'> 
.projects {
  .wrapper {
    width:1240px;
    // height:500px;
    // background-color: teal;
    .title {
      font-size:20px;
      line-height: 4em;
      border-bottom: 1px solid #f4f4f4;
    }
    .project {
      cursor: pointer;
      display: flex;
      padding: 1em 0;
      border-bottom: 1px solid #f4f4f4;
      .left {
        width:300px;
        height:200px;
        background-color: #f4f4f4;
        border-radius: 5px;
        overflow: hidden;
      }
      .right {
        flex: 1;
        // background-color: teal;
        padding: 0 2em;
        .name {
          font-weight: 500;
          font-size:15px;
        }
        .time {
          margin: 1em 0;
        }
        .content {
          line-height: 2em;
        }
      }
    }
  }
}
</style>

